package com.cyy.myapp;

import com.cyy.myapp.entity.User;
import com.cyy.myapp.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class HelloWorldController {

    private final UserRepository userRepository;

    @GetMapping("/")
    public String helloWorld() {
        System.out.println("hello world");
        return "Hi, World!";
    }

    @GetMapping("user")
    public List<User> list(){
        return userRepository.findAll();
    }

    @PostMapping("user")
    public User createUser(User user){
        return userRepository.save(user);
    }

}
